package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.CmsRecord;
import com.example.demo.common.Response;
import com.example.demo.service.CmsRecordService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "开房记录管理")
@RestController
@RequestMapping("/category")
public class CmsRecordController {

	@Autowired
	CmsRecordService recordService;
	
	@ApiOperation(value = "列出所有开房记录")
	@GetMapping("/All")
	public Response<List<CmsRecord>> findAll(){
		if(global.key==1) {
		List<CmsRecord> all = recordService.findAll();
		return Response.ok(all);}
		return null;
	}
	
	@ApiOperation(value = "按身份证来找出中开房记录")
	@GetMapping("/select")
	public Response<CmsRecord> selectById(String idCard){
		if(global.key==1) {
		CmsRecord data = recordService.selectById(idCard);
		return Response.ok(data);}
		return null;
	}
	
	@ApiOperation(value = "按身份证来删除开房记录")
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(String idCard){
		if(global.key==1) {
		int count = recordService.deleteById(idCard);
		return Response.ok("删除成功"+count);}
		return null;
	}
	
	@ApiOperation(value = "更改旅客开房记录")
	@PostMapping("/saveOrUpdate")
	public Response<String> saveOrUpdate(CmsRecord record){
		if(global.key==1) {
		recordService.saveOrUpdate(record);
		return Response.ok("success");}
		return Response.ok("fail");
	}
	
}
